import React, { Component } from 'react'

class Child extends Component {

	constructor(props) {
		super(props);
		this.state = {
			msg: "子组件msg"
		};
	}

	childFn = () => {
		this.props.parentFn(this.state.msg);
	}

	render() {
		const { msg } = this.props;
		return (
			<div>
				{msg} -- <button onClick={this.childFn}>调用父组件fn</button>
			</div>
		)
	}
}

export default class Parent extends Component {

	constructor(props) {
		super(props);
		this.state = {
			count: 1,
			msg: "parent msg"
		}
	}

	render() {
		return (
			<div>
				<Child msg={this.state.msg} parentFn={this.parentFn.bind(this)}></Child>
			</div>
		)
	}

	parentFn(msg) {
		console.log(this.state.count, msg);
	}
}
